#include <stdio.h>
#include <pthread.h>

 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 int position = 1;
 
 typedef struct arg_thread
 {
	int valMax;
	char* nomThread;
 }
void * counting( void * arg )
{
int i,j;
j = (int) arg;
for ( i = 0; i <= j; i++ ) 
 {
  pthread_mutex_lock(&mutex);
  printf("Valeur : <%d>",i);
  pthread_mutex_unlock(&mutex);
 }
 return 0;
 }

 int main()
 {
 int res1, res2;
 pthread_t a_thread1, a_thread2,a_thread3;
 void *thread_result1, *thread_result2,*thread_result3;
 res1 = pthread_create( &a_thread1, NULL, counting, "Thr1" );
 res2 = pthread_create( &a_thread2, NULL, counting, "Thr2" );
 res2 = pthread_create( &a_thread3, NULL, counting, "Thr3" );
 pthread_join( a_thread1, &thread_result1 );
 pthread_join( a_thread2, &thread_result2 );
 pthread_join( a_thread2, &thread_result3 );
 printf( "count = %d\n", count );
 pthread_mutex_destroy(&mutex);
 return 0;
 }